package leetcode.offer_two_special.hash;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @author mazouri
 * @create 2021-09-09 23:46
 */
public class _33_groupAnagrams {
    public List<List<String>> groupAnagrams(String[] strs) {
        //eat ate eta
        HashMap<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String sorted = new String(chars);

            map.putIfAbsent(sorted, new ArrayList<>());
            map.get(sorted).add(str);
        }
        return new ArrayList<>(map.values());
    }
}
